from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    # 可选择不同浏览器：chromium、firefox、webkit
    browser = p.firefox.launch(headless=False)
    page = browser.new_page()

    # 打开百度并等待加载完成
    page.goto("https://www.baidu.com")
    page.wait_for_load_state("networkidle")

    # 打印页面标题和URL
    print("标题:", page.title())
    print("URL:", page.url)

    # 截图保存
    page.screenshot(path="baidu_sync.png")

    # 关闭浏览器
    browser.close()